package com.example.business.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.example.base.utils.SpringContextUtils;
import com.example.base.utils.TimeUtils;
import com.example.business.service.SysImgService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * <p>
 * 视频表
 * </p>
 *
 * @author xiong
 * @since 2024-01-27
 */

@Data
@ApiModel(description = "视频表")
@TableName("sys_video")
public class SysVideo implements Serializable {

    private static final long serialVersionUID = 1L;

        /**
    * 文件id
    */
    @TableId(value="id", type= IdType.AUTO)
    @ApiModelProperty(value = "文件id")
    private Integer id;
    /**
    * 视频名称
    */
    @ApiModelProperty(value = "视频名称")
    private String filename;
    /**
    * 视频大小
    */
    @ApiModelProperty(value = "视频大小")
    private Double filesize;
    /**
    * 视频路径
    */
    @ApiModelProperty(value = "视频路径")
    private String filepath;
    /**
    * 视频封面id
    */
    @ApiModelProperty(value = "视频封面id")
    private String fileimgid;
    /**
    * 视频秒数
    */
    @ApiModelProperty(value = "视频秒数")
    private Double filetime;
    /**
    * 视频m3u8地址
    */
    @ApiModelProperty(value = "视频m3u8地址")
    private String filem3u8;
    /**
    * 视频类型
    */
    @ApiModelProperty(value = "视频类型")
    private String filetype;
    /**
    * 创建时间
    */
    @ApiModelProperty(value = "创建时间")
    private Date createdate;
    /**
    * 逻辑删除
    */
    @ApiModelProperty(value = "逻辑删除")
    private Integer deleteStatus;
    /**
    * 更新时间
    */
    @ApiModelProperty(value = "更新时间")
    private Date updatetime;
    /**
    * 视频标题
    */
    @ApiModelProperty(value = "视频标题")
    private String filetitle;
    /**
    * 视频副标题
    */
    @ApiModelProperty(value = "视频副标题")
    private String filesubtitle;
    /**
    * 视频介绍
    */
    @ApiModelProperty(value = "视频介绍")
    private String filenote;
    /**
    * 用户id
    */
    @ApiModelProperty(value = "用户id")
    private String userid;
    /**
    * 是否私密
    */
    @ApiModelProperty(value = "是否私密")
    private Integer isSm;
    /**
    * md5值
    */
    @ApiModelProperty(value = "md5值")
    private String filemd5;

    @ApiModelProperty(value = "播放次数")
    private Integer palyernum;

    @TableField(exist = false)
    private String imgBase64;

    @TableField(exist = false)
    private String timeStr;

    @TableField(exist = false)
    private String createTimeStr;

    public String getCreateTimeStr() {
        return TimeUtils.dateFormatAgo(this.createdate);
    }

    public String getTimeStr(){
        return convertSecondsToTimeFormat(this.filetime);
    }

    private String convertSecondsToTimeFormat(double seconds) {
        int intValue = (int) seconds;
        int hour = intValue / 3600;
        int minute = (intValue % 3600) / 60;
        int second = intValue % 60;

        return String.format("%02d:%02d:%02d", hour, minute, second);
    }

    public String getImgBase64() {
        if(StringUtils.isNotBlank(this.fileimgid)){
            SysImgService sysImgService=SpringContextUtils.getBean(SysImgService.class);
            SysImg sysImg=sysImgService.getById(this.fileimgid);
            return "data:image/jpeg;base64,"+sysImg.getBase64str();
        }
        return "";
    }
}
